import turtle
import time

# 创建一个窗口和画笔
screen = turtle.Screen()
screen.bgcolor("white")

# 创建表盘
clock_face = turtle.Turtle()
clock_face.speed(0)
clock_face.hideturtle()

# 绘制表盘
clock_face.penup()
clock_face.goto(0, -200)
clock_face.pendown()
clock_face.circle(200)

# 绘制刻度
for i in range(12):
    clock_face.penup()
    clock_face.goto(0, 0)
    clock_face.setheading(30 * i)
    clock_face.forward(180)
    clock_face.pendown()
    clock_face.forward(20)

# 创建时针和分针
hour_hand = turtle.Turtle()
minute_hand = turtle.Turtle()

hour_hand.shape("arrow")
minute_hand.shape("arrow")

hour_hand.shapesize(stretch_wid=0.5, stretch_len=6)
minute_hand.shapesize(stretch_wid=0.3, stretch_len=10)

hour_hand.speed(0)
minute_hand.speed(0)

# 更新时钟指针位置
def update_clock():
    while True:
        # 获取当前时间
        current_time = time.localtime()
        hour = current_time.tm_hour % 12
        minute = current_time.tm_min
        
        # 计算角度
        hour_angle = -(hour * 30 + minute * 0.5)
        minute_angle = -(minute * 6)
        
        # 设置指针方向
        hour_hand.setheading(hour_angle)
        minute_hand.setheading(minute_angle)
        
        # 每分钟更新一次
        time.sleep(60)

# 开始时钟
update_clock()

# 点击关闭窗口
screen.exitonclick()